import { login, } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'

export function handleLogin (userInfo: any) {
  const username = userInfo.account.trim()
  const password = userInfo.password
  return new Promise((resolve, reject) => {
    login(username, password)
      .then((res: any) => {
        setToken(res.data.accessToken)
        resolve(res)
      })
      .catch(error => {
        reject(error)
      })
  })
}

// 导出一个函数，用于处理登出操作
export function logoutSystem ():void  {
    // 移除token
    removeToken()
    // 清空localStorage
    localStorage.clear()
    // 跳转到登录页面
    window.location.href = '/login'
}
